import request from './request'
import type { User, UserForm, PageData, PageParams, ApiResponse } from '@/types'

// 获取用户列表
export const getUserList = (params: PageParams): Promise<PageData<User>> => {
  return request.get('/users', { params })
}

// 获取用户详情
export const getUserDetail = (id: number): Promise<User> => {
  return request.get(`/users/${id}`)
}

// 创建用户
export const createUser = (data: UserForm): Promise<User> => {
  return request.post('/users', data)
}

// 更新用户
export const updateUser = (id: number, data: UserForm): Promise<User> => {
  return request.put(`/users/${id}`, data)
}

// 删除用户
export const deleteUser = (id: number): Promise<ApiResponse> => {
  return request.delete(`/users/${id}`)
}

// 批量删除用户
export const batchDeleteUsers = (ids: number[]): Promise<ApiResponse> => {
  return request.delete('/users/batch', { data: { ids } })
}

// 重置用户密码
export const resetUserPassword = (id: number): Promise<ApiResponse> => {
  return request.post(`/users/${id}/reset-password`)
}

// 更新用户状态
export const updateUserStatus = (id: number, status: 'active' | 'inactive'): Promise<ApiResponse> => {
  return request.put(`/users/${id}/status`, { status })
}

